#include <iostream>
#include <cstdio>
#include <cstring>

#define MAXN 110

int a[MAXN][MAXN];
int memo[MAXN][MAXN] = {0};

//direction		     1  2  3   4 
const int dx[] = {0, 0, 0, 1, -1};
const int dy[] = {0, 1, -1, 0, 0};
int r,c;

using namespace std;

int dfs(int x, int y){
	if (memo[x][y])		return memo[x][y];
	memo[x][y] = 1;
	for (int i = 1; i <= 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (a[x][y] > a[nx][ny] && nx > 0 && ny > 0 && nx <= r && ny <= c){
			dfs(nx, ny);
			memo[x][y] = max(memo[x][y], memo[nx][ny] + 1);
		}
	}
	return memo[x][y];
}

int main(){
	cin >> r >> c;
	for (int i = 1; i <= r; i++){
		for (int j = 1; j <= c; j++){
	 		scanf ("%d",&a[i][j]);
		}
	}
	int ans = -1;
	for(int i = 1; i <= r; i++){
		for(int j = 1; j <= c; j++){
			ans = dfs(i, j) > ans ? dfs(i, j) : ans;
		}
	}
	
	cout << ans << endl;
	return 0;
}
